//
// Created by bianzheng on 2022/6/14.
//

#ifndef REC2_MIPS_FILEOUT_HPP
#define REC2_MIPS_FILEOUT_HPP

#include <vector>
#include <fstream>
#include <spdlog/spdlog.h>

#include "ConvertRatings.hpp"

namespace Rec2MIPS {
    void WriteFile(const char *output_fname, const char* output_dataset, const std::vector<RatingNum> &rating_num_l) {
        std::ofstream ratings_out(output_fname);
        const int report_every_ = 1000000;
        ratings_out << "userID,itemID,rating" << std::endl;

        const size_t n_rating = rating_num_l.size();
        for (size_t ratingID = 0; ratingID < n_rating; ratingID++) {
            if (ratingID % report_every_ == 0) {
                spdlog::info("write {} prec {}", output_dataset, 1.0 * ratingID / n_rating);
            }
            const RatingNum rating_num = rating_num_l[ratingID];
            ratings_out << rating_num.userID_ << "," << rating_num.itemID_ << "," << rating_num.rating_ << std::endl;
        }
        ratings_out.close();
    }
}
#endif //REC2_MIPS_FILEOUT_HPP
